#ifndef TCPUTILS_H
#define TCPUTILS_H

#include <QObject>
#include <QString>
#include <QTcpSocket>
#include <QTimer>
class tcputils : public QObject {
    Q_OBJECT
public:
    explicit tcputils( QObject* parent = nullptr );
    ~tcputils();
    bool getConnectStatus();
    void init();
    void close();
    void createDataRecv( const QString& ip, const int& id ); /*-<创建websocket连接 */
private:
    QTcpSocket* mSocket = Q_NULLPTR;
    QTimer*     m_timer;               /*-<周期重连Timer */
    bool        connectStatus = false; /*-< socket连接状态，连接成功：true；断开：false */

    QString        serverIP   = "";
    unsigned short serverPort = 8012;
    QString        agvId      = "0";

signals:
    void sigSendTips( QString );

private slots:
    void reconnect();      /*-<周期重连函数 */
    void onConnected();    /*-<socket建立成功后，触发该函数 */
    void onTextReceived(); /*-<收到Sev端的数s据时，触发该函数 */
    void onDisConnected(); /*-<socket连接断开后，触发该函数 */
    void onConnecterror( QAbstractSocket::SocketError& state );
};

#endif  // TCPUTILS_H
